package com.huang.dao;

import com.huang.pojo.User;
import com.huang.util.MybatisUtils;
import com.mysql.cj.protocol.a.MysqlBinaryValueDecoder;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserDaotext {
    static Logger logger = Logger.getLogger(UserDaotext.class);

    @Test
    public void text() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        User user = mapper.getUserid(1);
        System.out.println(user);
        sqlSession.close();
    }

    @Test
    public void log4jtest() {
        logger.info("info:进入了testLog4j");
        logger.debug("debug :进入了testLog4i");
        logger.error("error:进入了testLog4j");
    }

    @Test
    public void RowBounds() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        //RowBounds实现
       RowBounds rowBounds=new RowBounds(0,2);
       //java代码实现分页
        List<User> list = sqlSession.selectList("com.huang.dao.UserMapper.getUserRowbounds", null, rowBounds);
        for (User user : list) {
            System.out.println(user);
        }
        sqlSession.close();
    }

    @Test
    public void limit() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        Map<String, Integer> map = new HashMap<>();
        map.put("start", 0);
        map.put("end", 3);
        List<User> userLimit = mapper.getUserLimit(map);
        for (User user : userLimit) {
            System.out.println(user);
        }
        sqlSession.close();
    }
}
